var businessLogic = require('../../../utils/NetWork/Model/MainbusinessLogic.js')
var businessLogicvideo = require('../../../utils/NetWork/Model/VideobusinessLogic.js')
var common = require('../../../utils/common.js')
var ansheet = require('../../../utils/NetWork/ansheet.js')
var dataUrl = require('../../../utils/NetWork/sysJson.js')
// 这个页面可以理解为答题系统的数据中心
// 与答题组件交互
Page({
  /**
   * 页面的初始数据
   */
  data: {
    topic: [],//所有题目
    GreatEnigma: [],//渲染大题挂在页面上
    questions: [],//渲染小题挂在页面上
    zongxiaoti: [],
    datiSelect: "第一题",//判断是否选中
    datixuan: "0",//大题的选中项
    xiaotiSelect: 0,//判断是否选中
    xiaoxuan: "0",//小题的选中项
    daan: '请选择答案',
    daanmultiple: '请选择答案',
    queren: '未确认',
    tijiao: '未提交',
    inputValue: '',
    show: false,
    show2: false,
    like: false,
    color: false,
    isSpeaking: 1,
    testid: "",
    remarktype: "",
    collectid: "",//收藏的id
    //确定后的收藏
    queding_id: "",
    queding_haspg: "",
    queding_point: "",
    queding_statemark: "",
    parid: "",
    shitiided: "",
    peopleid: "",
    jlid: "",
    haspg: "",
    sureflag: "",//1是亮，0是暗,
    checkpointid: '',
    newid:''
  },
  /**
   * 1.进入页面获得考试id
   */
  onLoad: function (options) {
    // console.log(options);
    // 0 == 可以修改选择的
    // 1 == 可以增加、修改评语，得分
    // 2 == 不可以修改卷子
    // 3 == 不可以修改卷子而且有评语和得分
    // 4 == 不可以修改卷子,可以看到答案
    if (options.remarktype == 0) {
      console.log("==================可以修改选择的================");
    } else if (options.remarktype == 1) {
      console.log("==================可以增加、修改评语，得分==================");
    } else if (options.remarktype == 2) {
      console.log("==================不可以修改卷子==================");
    } else if (options.remarktype == 3) {
      console.log("==================不可以修改卷子而且有评语和得分==================");
    } else if (options.remarktype == 4) {
      console.log("==================不可以修改卷子,可以看到答案==================");
    }
    // console.log(options.examid);
    var userid = common.getStorageSync("userid")
    // 获取userid
    if (common.getStorageSync("role") == "学生") {
      // title     试卷标题 
      // remarktype  答题形式
      // examtype  考试形式   "examtype":"考试类型（1：作业，0：视频)"
      // examid   考试id(如果是观赏类, 传空)
      // parid  试卷id(如果是观赏类, 传空)
      this.setData({
        remarktype: options.remarktype,
        examid: options.examid,//获取考试Id
        examtype: options.examtype,
        parid: options.parid,
        name: userid,//学生的姓名就是自己的id
        checkpointid: options.checkpointid,
        videoid: options.video,
        passscore: options.passscore,
        type: options.type
      })
    } else {
      this.setData({
        remarktype: options.remarktype,
        examid: options.examid,
        examtype: options.examtype,
        checkpointid: options.checkpointid,
        parid: options.parid,
        videoid: options.video,
        passscore: options.passscore,
        type: options.type,
        name: options.name == undefined ? "" : options.name,//老师姓名就是老子名字
        peopleid: options.peopleid == undefined ? "" : options.peopleid,
        jlid: options.jlid == undefined ? "" : options.jlid
      })
    }
    wx.setNavigationBarTitle({
      title: options.title//页面标题为路由参数
    })
    console.log(this.data.examid);
    this.dataCenter();
    this.already()
  },
  //8.3.4 查询该场考试是否已经进入过
  already: function () {
    if (this.data.remarktype == 0) {
      let params = { "orgid": this.data.orgid, "userid": this.data.userid, "searchField": "peopleid,examid", "searchValue": this.data.userid + "," + this.data.examid }
      businessLogic.QueryPerson(params, (res) => {
        if (res == '' || res == undefined) {
          let InfoJson = ' {"orgid":"' + this.data.orgid + '", "userid":"' + this.data.userid + '", "peopleid": "' + this.data.userid + '", "examid":" ' + this.data.examid + '", "classid": "97678a51-f702-4181-8750-881b72a1e665", "statemark": "0","examtype":"1","iscomplete":"0"}';
          let params2 = { "orgid": this.data.orgid, "userid": this.data.userid, "InfoJson": InfoJson }
         
          businessLogic.SubmitUpdated(params2, (res2) => {
            console.log("hhhhhhh", res2)
            this.setData({
              newid: res2.id
            })
          })
        } else {
          this.setData({
            newid: res[0].id
          })
        }
        console.log("ffffffffffff", res)
      })
    }
  },
  //=========================================###获取题目
  //2.取出个人信息，机构信息，题目信息
  dataCenter: function () {
    var orgid = common.getStorageSync("orgid")
    var userid = common.getStorageSync("userid")
    var role = common.getStorageSync("role")
    this.setData({
      orgid: orgid,
      userid: userid,
      role: role
    });
    this.paridpost();
  },
  //3.获取题目id，获取考卷
  paridpost: function () {
    let params = { "orgid": this.data.orgid, "userid": this.data.userid, "id": this.data.parid }
    // 8.2.1-2 查询考试试卷内容（已测试）	
    businessLogic.Queryontent1(params, (res) => {
      //console.log("luan",res)
      this.setData({
        topic: res,
      });
      //将整张卷子提交topic这个数据中心
      this.dati(res);//4.把题目信息交给答题组件渲染
    })
  },

  //4.将题目信息渲染成 大题和小题
  dati: function (res) {
    // 对数据进行遍历出 大题和小题
    ansheet.titleInformation(res, (xinxi) => {
      // console.log(xinxi);
      // console.log(xinxi.blxiaoti);
      // console.log(xinxi.datida);
      //5.默认选择第一道小题
      this.setData({
        GreatEnigma: xinxi.datida,//渲染大题挂在页面上
        zongxiaoti: xinxi.blxiaoti,//获取大题中有多少小题
      })
    })

    this.xuanxiaoti(0)//选中第一大题信息并渲染
  },

  //6.渲染小题挂在页面上
  xuanxiaoti: function (num) {
    this.setData({
      questions: this.data.zongxiaoti[num] == undefined ? "" : this.data.zongxiaoti[num],
    })

    // =============================
    this.subject.examid(this.data.examid);//讲试题id，传给大题，有问题
    // =============================

    var timurt = this.subject.timu(0, 0, this.data.topic, this.data.remarktype, this.data.examid);//把所有的题目交给subject组件,并去获取第一题
    let testid = timurt[0];
    this.setData({
      testid: testid,
      sureflag: timurt[1]
    });

    // if (this.data.remarktype == 4) {
    //   // 4 == 不可以修改卷子, 可以看到答案
    // } else {
    this.findInfoTempListByClassid(testid);
    // }

    this.chacollect(testid);//通过试题id，查询是否收藏
  },

  //8.3.1 查询试题是否被做过及试题的答案（看是否有返回值 ?）（已测试）	
  findInfoTempListByClassid: function (testid) {
    console.log(testid);
    let renid = "";
    if (this.data.peopleid == "" || this.data.peopleid == undefined) {
      renid = this.data.userid;
    } else {
      renid = this.data.peopleid;
    }
    let params = { "orgid": this.data.orgid, "userid": renid, "searchField": "peopleid,examid,testid", "searchValue": "" + this.data.name + "," + this.data.examid + "," + testid + "" }
    //console.log("8.3.1",params)
    businessLogic.DoneAnd(params, (res) => {
      // common.showLoading("加载中", "loading");
      // console.log(res);
      if (res == undefined) {
        this.setData({
          shitiided: "",//查询试题id
        })
      } else {
        this.setData({
          shitiided: res.id,//查询试题id
        })
        this.subject.Newstext(res)//试题的答案返回给
      }
    });
  },
  //==============================================####选择题目的确定按钮
  //大题选择
  chooseDati: function (data) {
    var that = this;
    that.setData({//把选中值放入判断值
      datiSelect: data.currentTarget.dataset.select,
      datixuan: data.currentTarget.dataset.index
    })
  },
  //小题选择
  chooseXiaoti: function (data) {
    console.log(data);
    var that = this;
    that.setData({//把选中值放入判断值
      xiaotiSelect: data.currentTarget.dataset.xtselect,
      xiaoxuan: data.currentTarget.dataset.xtselect
    })
  },
  //大题确认按钮
  button: function () {
    this.xuanxiaoti(this.data.datixuan);
    this.setData({
      show: false,
      show2: false,
      datixuan: this.data.datixuan,
    })
    console.log("大题:" + this.data.datixuan);
    var timurt = this.subject.timu(this.data.datixuan, 0, this.data.topic, this.data.remarktype, this.data.examid);
    let testid = timurt[0];
    this.setData({
      testid: testid,
      sureflag: timurt[1]
    })

    // if (this.remarktype == 4) {

    // } else {
    this.findInfoTempListByClassid(testid);
    // }
    this.chacollect(testid);//通过试题id，查询是否收藏
  },
  // 小题确认按钮
  xiaobutton: function () {
    console.log("小题:" + this.data.xiaoxuan)
    this.setData({
      show: false,
      show2: false,
      xiaoxuan: this.data.xiaoxuan,
    })
    var timurt = this.subject.timu(this.data.datixuan, this.data.xiaoxuan, this.data.topic, this.data.remarktype, this.data.examid);
    let testid = timurt[0];
    this.setData({
      testid: testid,
      sureflag: timurt[1]

    })
    // if (this.data.remarktype == 4) {

    // } else {
    this.findInfoTempListByClassid(testid);
    // }
    this.chacollect(testid);//通过试题id，查询是否收藏
  },

  //==============================================####收藏与大小题的显示
  //查询是否收藏
  chacollect: function () {
    var timestamp = (new Date()).valueOf();
    common.setStorage("kaisi", timestamp);

    let params = { userid: this.data.userid, orgid: this.data.orgid, searchField: "peopleid,testid", searchValue: "" + this.data.userid + "," + this.data.testid + "" }
    businessLogic.CollectionOfPapers(params, (res) => {
      // console.log("查看是否收藏", res == undefined ? "无" : res.iscollect);
      // 0是没有收藏
      // 1是收藏
      if (res == undefined) {
        this.setData({
          like: false,
        })
      } else {
        if (res.iscollect == 1) {
          this.setData({
            like: true,
            collectid: res.id
          })
        } else {
          this.setData({
            like: false,
            collectid: res.id
          })
        }
      }
    });
  },
  //点击收藏的方法
  collect: function () {
    this.setData({
      like: !this.data.like
    })
    if (this.data.like == true) {
      // console.log(this.data.like);
      // console.log(this.data.testid);
      // 1收藏
      // 0取消收藏
      let InfoJson = ' {"orgid":"' + this.data.orgid + '", "userid":"' + this.data.userid + '", "peopleid": "' + this.data.userid + '", "testid":" ' + this.data.testid + '", "iscollect": "1", "id": "' + this.data.collectid + '"}';
      let params = {
        "InfoJson": InfoJson, "orgid": this.data.orgid, "userid": this.data.userid
      }
      businessLogic.CancelTheCollection(params, (res) => {
        // console.log(res);
      });
    } else {
      // console.log(this.data.like);
      // console.log(this.data.testid);
      let InfoJson = ' {"orgid":"' + this.data.orgid + '", "userid":"' + this.data.userid + '", "peopleid": "' + this.data.userid + '", "testid":" ' + this.data.testid + '", "iscollect": "0", "id": "' + this.data.collectid + '"}';

      let params = {
        "InfoJson": InfoJson, "orgid": this.data.orgid, "userid": this.data.userid
      }
      businessLogic.CancelTheCollection(params, (res) => {
        console.log(res);
      });
    }
  },
  // 点击大题出现
  onClickShow: function (e) {
    if (this.data.show2 == true) {
      this.setData({
        show2: false,
        show: !this.data.show
      })
    } else {
      this.setData({
        show: !this.data.show
      })
    }
  },

  // 点击小题出现
  onClickShow2: function (e) {
    if (this.data.show == true) {
      this.setData({
        show: false,
        show2: !this.data.show2
      })
    } else {
      this.setData({
        show2: !this.data.show2
      })
    }
  },

  //=====================================###点击确定，提交后产生的事件
  //提交的确定按钮
  sure: function () {
    //获取答案
    let sureAnswer = "";
    let daan = "";
    let score = "";
    let knowledgepoints = "";
    let parentid = "";
    let typeGail = "";
    let testid = "";
    if (this.data.sureflag == 1) {
      sureAnswer = this.subject.sure();

      daan = sureAnswer["mydata"];//答案
      score = sureAnswer["rubric"].score;//这道题的总分
      knowledgepoints = sureAnswer["rubric"].knowledgepoints;//测量主题的id
      parentid = "";
      testid = this.data.testid;


    } else {
      sureAnswer = this.subject.surezonghe();

      daan = sureAnswer["mydata"];//答案
      score = sureAnswer["csub"].score;//这道题的总分
      knowledgepoints = sureAnswer["csub"].knowledgepoints;//测量主题的id
      parentid = sureAnswer["rubric"].id;

      testid = sureAnswer["csub"].id;
    }





    if (this.data.sureflag == 1) {
      typeGail = sureAnswer["rubric"].typecode;//获取填空的题目的类型
    } else {
      typeGail = sureAnswer["csub"].typecode;//获取填空的题目的类型
      typeGail = ansheet.testtype(typeGail);
    }

    for (let i = 0; i < typeGail.length; i++) {
      if (typeGail[i] == "填空题_键盘输入类型") {
        typeGail[i] = "1";
      } else if (typeGail[i] == "填空题_语言输入类型") {
        typeGail[i] = "3";
      } else if (typeGail[i] == "填空题_手绘输入类型") {
        typeGail[i] = "2";
      }
    }
    let typecode = "";
    if (this.data.sureflag == 1) {
      typecode = sureAnswer["rubric"].typecode;//获取题目的类型
    } else {
      typecode = sureAnswer["csub"].typecode;//获取题目的类型
      typecode = ansheet.testtype(typecode);
    }
    if (typecode == "填空题_键盘输入类型") {
      typecode = "2";
    } else if (typecode == "填空题_语言输入类型") {
      typecode = "2";
    } else if (typecode == "填空题_手绘输入类型") {
      typecode = "2";
    } else if (typecode == "单选题") {
      typecode = "0";
    } else if (typecode == "多选题") {
      typecode = "1";
    } else {
      typecode = "2";
    }

    let newdaan = [];
    let weidaan = [];
    let newdaan2 = [];
    let weidaan2 = [];

    if (typecode == "0" || typecode == "1") {
      weidaan = daan;
      weidaan2 = daan;
    } else {
      let newdaansuan = {};
      let newdaansuan2 = {};
      for (var a = 0; a < daan.length; a++) {
        let c = "" + a + "";
        newdaansuan = '{' + "\\" + '"data' + "\\" + '":' + "\\" + '"' + daan[a] + '' + "\\" + '",' + "\\" + '"type' + "\\" + '":' + typeGail[a] + ',' + "\\" + '"order' + "\\" + '":' + c + '},';
        newdaan = newdaan + newdaansuan
        newdaansuan2 = '{"data":"' + daan[a] + '","type":' + typeGail[a] + ',"order":' + c + '},';
        newdaan2 = newdaan2 + newdaansuan2
      }
      newdaan = newdaan.substring(0, newdaan.length - 1);
      weidaan = newdaan + weidaan;
      weidaan = "[" + weidaan + "]";

      newdaan2 = newdaan2.substring(0, newdaan2.length - 1);
      weidaan2 = newdaan2 + weidaan2;
      weidaan2 = "[" + weidaan2 + "]";
    }
    if (weidaan == "" || weidaan == "1" || weidaan2 == "" || weidaan2 == "1") {
      common.showToast("请输入答案", "none");
    } else {
      // console.log("weidaan2", weidaan2);
      // 8.3.2.1  第一次点击确认后查询人员试题表（）
      let params = { "peopleid": this.data.userid, "orgid": this.data.orgid, "examid": this.data.examid, "testid": testid, "stuanswer": weidaan2, "score": score, "modelname": "人员试题记录系统模型", "typecode": typecode }
      businessLogic.AddExamination(params, (res) => {
        common.showLoading("加载中", "loading");
        console.log("8.3.2.1", res);
        this.setData({
          queding_id: res.result.id,
          queding_haspg: res.infos[0].haspg,
          queding_point: res.infos[0].point,
          queding_statemark: res.infos[0].statemark,
        })
        if (res.result.flag == 1) {
          var statemarktype = "";
          if (res.infos[0].statemark == null) {
            statemarktype = 0;
          } else {
            statemarktype = res.infos[0].statemark;
          }

          // 8.3.2.2  点击确认后更新人员试题表
          let InfoJson = '{"id":"' + res.result.id + '","type":"' + statemarktype + '"}';
          let params = { "InfoJson": InfoJson, "userid": this.data.userid, "orgid": this.data.orgid };
          businessLogic.UpdateStaffTest(params, (resa) => {
            common.showLoading("加载中", "loading");
            console.log("8.3.2.2 ", resa);
            if (resa.flag == 1) {
              console.log("shitiided", this.data.shitiided)
              // this.subject.quesure(, , , , , , , , );
              // quesure: function (, , , , , , , , )
              let classid = res.result.id;
              let statemark = statemarktype;
              let parid = this.data.parid;
              let examid = this.data.examid;
              let daan = weidaan;
              let point = res.infos[0].point;

              let shitiided = this.data.shitiided;
              let iscorrect = 0;

              if (score == "") {
                score = 0;
              }
              if (this.data.role == "学生") {
                //8.3.2.3 点击确认后更新人员试题记录表（）
                let kaisi = common.getStorageSync("kaisi");
                let timestamp = (new Date()).valueOf();
                let dotime = timestamp - kaisi;

                var timestamp = Math.round(new Date().getTime() / 1000).toString();
                let InfoJson = '{"orgid":"' + this.data.orgid + '","userid":"' + this.data.userid + '","classid":"' + classid + '","id":"' + shitiided + '","addtime":"' + timestamp + '","haspg":"0","hastj":"0","statemark":"' + statemark + '","dotime":"' + dotime + '","paperid":"' + parid + '","examid":"' + examid + '","peopleid":"' + this.data.userid + '","answer":"' + sureAnswer["rubric"].answer + '","iscorrect":"' + iscorrect + '","newstext":"' + daan + '","substates":"' + sureAnswer["rubric"].substate + '","point":' + point + ',"score":"' + score + '","testid":"' + testid + '","parentid":"' + parentid + '"}';
                let params = { "InfoJson": InfoJson, "userid": this.data.userid, "orgid": this.data.orgid, classid: classid };
                businessLogic.UpdateStaffTestnew(params, (resaa) => {
                  common.showLoading("加载中", "loading");
                  console.log("8.3.2.3", resaa);
                  common.showToast("已确定", "none");
                  if (resaa.flag == 1) {

                    // ==========================薄弱知识点的接口
                    // haspg  1 批改 0 属于不批改
                    // 学生 1调用   老师 0 调用

                    if (res.infos[0].haspg == 1 && this.data.role == "学生") {
                      // 8.10.2 查询该人是否有该薄弱知识点的接口（已测试）
                      let chaxun = { "searchField": "peopleid, knowledgepoints", "searchValue": "" + this.data.userid + "," + knowledgepoints + "", "orgid": this.data.orgid, userid: this.data.userid }
                      businessLogic.QueryWhethernew(chaxun, (fres) => {
                        console.log("8.10.2", fres);
                        if (fres.result.flag == 1) {
                          let id = "";
                          let acount = "1";//题数               
                          let wcount = "0";//错题数

                          if (fres.infos == "" || fres.infos == undefined) {
                            id = "";
                            acount = 1;
                            if (res.infos[0].statemark == 0) {
                              wcount = 1;
                            } else {
                              wcount = 0
                            }
                          } else {
                            id = fres.infos[0].id;
                            acount = fres.infos[0].acount + 1;
                            let newc = fres.infos[0].wcount
                            // console.log("cg");
                            // statemark 0 错
                            if (res.infos[0].statemark == 0) {
                              wcount = newc + 1;
                            } else {
                              wcount = newc
                            }
                          }
                          let jilu = '{"orgid":"' + this.data.orgid + '","userid":"' + this.data.userid + '","classid":"e956a1e0-52a2-4a71-a5c6-3ffc6852877c","id":"' + id + '","peopleid":"' + this.data.userid + '","knowledgepoints":"' + knowledgepoints + '","acount":"' + acount + '","wcount":"' + wcount + '"}';
                          let jilus = { "InfoJson": "" + jilu + "", "userid": "" + this.data.userid + "", "orgid": "" + this.data.orgid + "" }
                          businessLogic.InterfaceWeakKnowledgenew(jilus, (cres) => {
                            console.log(cres);
                          });
                        }
                      });
                    }
                    else if (res.infos[0].haspg == 0 && this.data.role == "老师") {
                      // 8.10.2 查询该人是否有该薄弱知识点的接口（已测试）
                      let chaxun = { "searchField": "peopleid, knowledgepoints", "searchValue": "" + this.data.userid + "," + knowledgepoints + "", "orgid": this.data.orgid, userid: this.data.userid }
                      businessLogic.QueryWhethernew(chaxun, (fres) => {
                        console.log("8.10.2", fres);
                        if (fres.result.flag == 1) {
                          let id = "";
                          let acount = "1";//题数               
                          let wcount = "0";//错题数

                          if (fres.infos == "" || fres.infos == undefined) {
                            id = "";
                            acount = 1;
                            if (res.infos[0].statemark == 0) {
                              wcount = 1;
                            } else {
                              wcount = 0
                            }
                          } else {
                            id = fres.infos[0].id;
                            acount = fres.infos[0].acount + 1;
                            let newc = fres.infos[0].wcount
                            console.log("cg");
                            // statemark 0 错
                            if (res.infos[0].statemark == 0) {
                              wcount = newc + 1;
                            } else {
                              wcount = newc
                            }
                          }
                          let jilu = '{"orgid":"' + this.data.orgid + '","userid":"' + this.data.userid + '","classid":"e956a1e0-52a2-4a71-a5c6-3ffc6852877c","id":"' + id + '","peopleid":"' + this.data.userid + '","knowledgepoints":"' + knowledgepoints + '","acount":"' + acount + '","wcount":"' + wcount + '"}';
                          let jilus = { "InfoJson": "" + jilu + "", "userid": "" + this.data.userid + "", "orgid": "" + this.data.orgid + "" }
                          businessLogic.InterfaceWeakKnowledgenew(jilus, (cres) => {
                            console.log(cres);
                          });
                        }
                      });
                    }

                    // ==========================
                  } else {

                  }

                });
              } else if (this.data.role == "老师") {
                // 这边是批改
                // 6.8.3.3 点击确认后更新人员试题记录表（）
                let py = this.subject.getdepy();

                let defen = py[0];//总分
                let pinjia = py[1];//评价
                let point = py[2];//得分
                let statemark = "";//错误

                if (defen == point) {
                  statemark = 0;
                } else {
                  statemark = 1;
                }

                let queding = '{"orgid":"' + this.data.orgid + '","userid":"' + this.data.userid + '","classid":"' + res.result.id + '","id":"' + shitiided + '","point":"' + point + '","haspg":"1","hastj":"0","statemark":"' + statemark + '","say":"' + pinjia + '","pgmemberid":"' + this.data.userid + '"}';
                let quezhi = { "InfoJson": queding, "userid": "" + this.data.userid + "", classid: "" + res.result.id + "", orgid: "" + this.data.orgid + "" }

                // 6.8.3.3 点击确认后更新人员试题记录表
                businessLogic.DetermineTheUpdate(quezhi, (cres) => {
                  common.showLoading("加载中", "loading");
                  console.log(cres);
                  common.hideLoading();
                  common.showToast("已确定", "none");
                });



                // 先不做判断
                // this.findInfoTempListByClassid(testid);

              }


            }
          });
        }
      });

    }
  }, //确定提交

  //==========
  //提交按钮
  submit: function () {
    common.modalcnt("是否提交试卷", "确定将无法更改哦~");
    this.modalcnttiao("是否提交试卷", "确定将无法更改哦~", "取消", "确定");
  },
  //选择弹窗
  modalcnttiao: function (title, content, cancelText, confirmText, ) {
    // console.log(tiaozhuan);
    var that = this;

    wx.showModal({
      title: title,
      content: content,
      cancelText: cancelText,
      confirmText: confirmText,
      success: function (res) {
        if (res.confirm) {
          that.tiao();
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  tiao: function () {
    this.modalcnttiao2("是否提交试卷", "第二次提醒，您是否要提交~", "取消", "确定");
  },
  //第二次提醒是否提交
  modalcnttiao2: function (title, content, cancelText, confirmText, ) {
    // console.log(tiaozhuan);
    var that = this;

    wx.showModal({
      title: title,
      content: content,
      cancelText: cancelText,
      confirmText: confirmText,
      success: function (res) {
        if (res.confirm) {
          that.diertiao();
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },

  //提交
  diertiao: function () {
    // 8.3.3.1  点击提交后统计分数（如果这张卷子不是立即批改的话，score返回0，如果是立即批改的话则返回你获得的总分）

    // peopleid	答题人id
    // orgid	机构id
    // examid	 考试Id
    // paperid  试卷id
    // userid	登录人id
    // type 学生为 0 老师为 1 
    let typex = "";
    if (this.data.role == "学生") {
      typex = 0;
    } else {
      typex = 1;

    }

    let renid = "";
    if (this.data.peopleid == "" || this.data.peopleid == undefined) {
      renid = this.data.userid;
    } else {
      renid = this.data.peopleid;
    }

    let params = { "peopleid": renid, "orgid": this.data.orgid, "examid": this.data.examid, paperid: this.data.parid, userid: this.data.userid, type: typex };
    businessLogic.Submitpapers(params, (resaa) => {
      console.log("8.3.3.1", resaa);
      this.setData({
        haspg: resaa[0].point,
      })

      console.log(this.data.haspg);

      // haspg 0 是否批改 1代表自动批改
      // point 0 分
      //如果批改的话就调8.3.3.3

      // if (resaa[0].haspg == 1) {
      // 8.3.3.2  点击提交后统计评价（试卷自动批改的话调用）
      let params = { "peopleid": this.data.userid, "orgid": this.data.orgid, "examid": this.data.examid, "paperid": this.data.parid, "userid": this.data.userid, "type": 0 };
      businessLogic.Submitpaperspj(params, (pj) => {
        console.log("8.3.3.2", pj);


        if (this.data.role == "学生") {
          // 8.3.3.3  点击提交后更新人员考试表（）
          let kaisi = common.getStorageSync("kaisi");
          let timestamp = (new Date()).valueOf();
          let dotime = timestamp - kaisi;

          let InfoJson = '{"orgid":"' + this.data.orgid + '","userid":"' + this.data.userid + '","classid":"97678a51-f702-4181-8750-881b72a1e665", "id":"' + this.data.newid+'", "peopleid":"' + this.data.userid + '", "examid":"' + this.data.examid + '","statemark":"0", "examtype":"' + this.data.examtype + '", "iscomplete":"1", "dotime":"' + dotime + '", "score":"' + resaa[0].score + '"}';
          let params = { "InfoJson": InfoJson, "orgid": this.data.orgid, userid: this.data.userid };
          businessLogic.Submitpapersgx(params, (gx) => {
            console.log("8.3.3.3 ", gx);
            if (gx.flag == 1) {
              var ispass = '';
              if (this.data.examtype == 0) {
                //5.8增加个人视频关卡考试记录表
                if (this.data.type == 1) {
                  ispass = 1;
                }
                else {
                  if (this.data.passscore <= resaa[0].score) {
                    ispass = 1;
                  } else {
                    ispass = 0;
                  }
                }
                let InfoJson = '{"orgid":"' + this.data.orgid + '","userid":"' + this.data.userid + '","classid":"983dd930-6dd4-4346-92e1-4410db1ca0a2", "peopleid":"' + this.data.userid + '", "videoid":"' + this.data.videoid + '", "time":"' + dotime + '", "examscore":"' + resaa[0].score + '","checkpointid":"' + this.data.checkpointid + '","ispass":"' + ispass + '"}';
                let videoparams = { "InfoJson": InfoJson, "orgid": this.data.orgid, userid: this.data.userid };
                businessLogicvideo.AddVideoLevelList(videoparams, (videores) => {
                  console.log("5.8", videores)
                })
                let InfoJson2 = '{"orgid":"' + this.data.orgid + '","userid":"' + this.data.userid + '","classid":"f9257749-afc3-4412-a99f-33f081cd7141", "peopleid":"' + this.data.userid + '", "videoid":"' + this.data.videoid + '", "stime":"' + kaisi + '", "etime":"' + timestamp + '","type":"1","score":"' + resaa[0].score + '"}';
                let vvparams = { "InfoJson": InfoJson2, "orgid": this.data.orgid, userid: this.data.userid };
                businessLogicvideo.AddPeVideo(vvparams, (res) => {
                  console.log("5.9", res)
                })
                wx.navigateBack({
                  delta: 1
                })
              } else {
                wx.switchTab({
                  url: '../teacherOrder/teacherOrder',
                  fail: function () {
                    console.info("跳转失败")
                  }
                })
              }
            }
          });

        } else if (this.data.role == "老师") {

          let InfoJson = '{"orgid":"' + this.data.orgid + '","userid":"' + this.data.userid + '","classid":"97678a51-f702-4181-8750-881b72a1e665", "id":"' + this.data.jlid + '", "iscomplete":"1", "statemark":"1","rank":"' + this.data.haspg + '","pgmemberid":"' + this.data.userid + '", "score":"' + resaa[0].score + '"}';
          let params = { "InfoJson": InfoJson, "orgid": this.data.orgid, userid: this.data.userid };
          businessLogic.Submitpapersgx(params, (gx) => {
            console.log("6.8.4.2 ", gx);
            if (gx.flag == 1) {
              var ispass = '';
              if (this.data.examtype == 0) {
                //5.8增加个人视频关卡考试记录表
                if (this.data.type == 1) {
                  ispass = 1;
                }
                else {
                  if (this.data.passscore <= resaa[0].score) {
                    ispass = 1;
                  } else {
                    ispass = 0;
                  }
                }
                let InfoJson = '{"orgid":"' + this.data.orgid + '","userid":"' + this.data.userid + '","classid":"983dd930-6dd4-4346-92e1-4410db1ca0a2", "peopleid":"' + this.data.userid + '", "videoid":"' + this.data.videoid + '", "time":"' + dotime + '", "examscore":"' + resaa[0].score + '","checkpointid":"' + this.data.checkpointid + '","ispass":"' + ispass + '"}';
                let videoparams = { "InfoJson": InfoJson, "orgid": this.data.orgid, userid: this.data.userid };
                businessLogicvideo.AddVideoLevelList(videoparams, (videores) => {
                  console.log("5.8", videores)
                })
                let InfoJson2 = '{"orgid":"' + this.data.orgid + '","userid":"' + this.data.userid + '","classid":"f9257749-afc3-4412-a99f-33f081cd7141", "peopleid":"' + this.data.userid + '", "videoid":"' + this.data.videoid + '", "stime":"' + kaisi + '", "etime":"' + timestamp + '","type":"1","score":"' + resaa[0].score + '"}';
                let vvparams = { "InfoJson": InfoJson2, "orgid": this.data.orgid, userid: this.data.userid };
                businessLogicvideo.AddPeVideo(vvparams, (res) => {
                  console.log("5.9", res)
                })
                wx.navigateBack({
                  delta: 1
                })
              } else {
                wx.switchTab({
                  url: '../teacherOrder/teacherOrder',
                  fail: function () {
                    console.info("跳转失败")
                  }
                })
              }

            }

          });



        }

      });
      // }else{

      // }



    });

  },
  // ========================================================= 这边要注册组件
  onReady: function () {
    //获得subject组件
    this.subject = this.selectComponent("#subject");
  },

})